package com.ciccwm.auth.model;

import java.util.Map;

/**
 * 授权码数据记录
 */
public record AuthCodeData(
    String clientId,
    String redirectUri,
    long timestamp
) {
    /**
     * 创建授权码数据
     */
    public static AuthCodeData of(String clientId, String redirectUri) {
        return new AuthCodeData(clientId, redirectUri, System.currentTimeMillis());
    }

    /**
     * 转换为Map
     */
    public Map<String, String> toMap() {
        return java.util.Map.of(
            "client_id", clientId,
            "redirect_uri", redirectUri,
            "timestamp", String.valueOf(timestamp)
        );
    }

    /**
     * 从Map创建
     */
    public static AuthCodeData fromMap(java.util.Map<Object, Object> map) {
        return new AuthCodeData(
            (String) map.get("client_id"),
            (String) map.get("redirect_uri"),
            Long.parseLong((String) map.get("timestamp"))
        );
    }
} 
